package com.webinsky.common.utils.db;

public class BasicSqlProvider {
	protected String tablename;
	
	public BasicSqlProvider(String tablename){
		this.tablename = tablename;
	}
	
	protected SQLBuilder getUpdateBuilder(){
		SQLBuilder sqlBuilder = new SQLBuilder();
		return sqlBuilder.UPDATE(tablename);
	}
	
	protected SQLBuilder getInsertBuilder(){
		SQLBuilder sqlBuilder = new SQLBuilder();
		return sqlBuilder.INSERT_INTO(tablename);
	}	
	
	protected SQLBuilder getDeleteBuilder(){
		SQLBuilder sqlBuilder = new SQLBuilder();
		return sqlBuilder.DELETE_FROM(tablename);
	}
	
	protected SQLBuilder getSelectBuilder( String ...columns ){
		SQLBuilder sqlBuilder = new SQLBuilder();
		sqlBuilder = sqlBuilder.FROM(tablename);
		sqlBuilder = sqlBuilder.SELECT(columns);
		return sqlBuilder;
	}
	
	protected String genSelectPage( Pagnation page, String ...columns ){
		SQLBuilder sqlBuilder = new SQLBuilder();
		sqlBuilder = sqlBuilder.FROM(tablename);
		sqlBuilder = sqlBuilder.SELECT(columns);
		String strSql = sqlBuilder.toString();
		if ( page != null ){
			strSql = PageHelper.startPage(strSql, page);
		}
		return strSql;
	}
}
